<html itemscope itemtype="http://schema.org/Article">
  <head>
  <title>Welcome to the Madrox Project!</title>
  <!-- BEGIN Pre-requisites -->
  <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js">
  </script>
  <script type="text/javascript">
	var stateToken;
	
    (function () {
      var po = document.createElement('script');
      po.type = 'text/javascript';
      po.async = true;
      po.src = 'https://plus.google.com/js/client:plusone.js?onload=start';
      var s = document.getElementsByTagName('script')[0];
      s.parentNode.insertBefore(po, s);
    })();
  </script>
  <!-- END Pre-requisites -->
</head>
	<body>
		<!-- Add where you want your sign-in button to render -->
		<div id="signinButton">
  		<span class="g-signin"
    		data-scope="https://www.googleapis.com/auth/plus.login"
    		data-clientid="509851416801-ac7tm0hhub28t5jd320s64j4f56oinfm.apps.googleusercontent.com"
    		data-redirecturi="postmessage"
    		data-accesstype="offline"
    		data-cookiepolicy="single_host_origin"
    		data-callback="signInCallback">
  		</span>
</div>
<div id="result">
</div>
	
<!-- Last part of BODY element in file index.html -->
<script type="text/javascript">
function signInCallback(authResult) {
  if (authResult['code']) {

    // Hide the sign-in button now that the user is authorized, for example:
    $('#signinButton').attr('style', 'display: none');

    // Send the code to the server
    $.ajax({
      type: 'POST',
      url: 'authTokenRequest',
      success: function(result) {
        // Handle or verify the server response if necessary.

        // Prints the list of people that the user has allowed the app to know
        // to the console.
        console.log(result);
        if (result['profile'] && result['people']){
          $('#results').html('Hello ' + result['profile']['displayName'] + '. You successfully made a server side call to people.get and people.list');
        } else {
          $('#results').html('Failed to make a server-side call. Check your configuration and console.');
        }
      },
      data: {access_token : authResult['id_token'], 
      	code : authResult['code'], 
      	state : stateToken}
    });
  }  else {
  	$.ajax({
      type: 'GET',
      url: 'authTokenRequest',
      contentType: 'application/octet-stream; charset=utf-8',
      success: function(result) {
        stateToken = result;
        console.log(result);
        if (result['profile'] && result['people']){
          $('#results').html('Hello ' + result['profile']['displayName'] + '. You successfully made a server side call to people.get and people.list');
        } else {
          $('#results').html('Failed to make a server-side call. Check your configuration and console.');
        }
      },
      processData: false,
      data: authResult['code']
    });
  }
}
</script>
</body>
</html>